package com.xtecher.app.base;

import android.app.Application;

import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.cookie.CookieJarImpl;
import com.zhy.http.okhttp.cookie.store.PersistentCookieStore;
import com.zhy.http.okhttp.https.HttpsUtils;
import com.zhy.http.okhttp.log.LoggerInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Application app启动时初始化类
 * Created by Luhao on 2017/2/22.
 */

public class BaseApplication extends Application {

    public static final String APP_ID = "wx7cbc38daea7f5de3";
    public static IWXAPI wxapi;

    @Override
    public void onCreate() {
        super.onCreate();
        /**
         * 配置OkHttpUtils 对应参数
         * 设置log
         * 设置连接超时时间
         * 设置读取超时时间
         * 设置cookie持久化
         * 设置可以访问所有的https网站
         */
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new LoggerInterceptor("Xtecher", true))
                .connectTimeout(5, TimeUnit.SECONDS)
                .readTimeout(5, TimeUnit.SECONDS)
                .cookieJar(new CookieJarImpl(new PersistentCookieStore(getApplicationContext())))
                .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                .build();
        OkHttpUtils.initClient(okHttpClient);

        wxapi = WXAPIFactory.createWXAPI(this, APP_ID, false);

        wxapi.registerApp(APP_ID);
    }
}
